package com.gitee.wsl.ext.collection

import com.gitee.wsl.ext.array.median


/*fun DoubleArray.median() = let { array ->
    val listSize = array.size
    val middle = listSize / 2

    if (listSize % 2 == 1)
        array[middle]
    else
        (array[middle - 1] + array[middle]) / 2.0
}*/

/**
 * Returns the difference between the `average()` and the `median()`.
 * A positive difference indicates a positive skewDifference, and negative indicates a negative skewDifference
 */
fun DoubleArray.skewDifference() = let { it.average() - it.median }
fun Iterable<Double>.skewDifference() = let { it.average() - it.median() }
fun Sequence<Double>.skewDifference() = toList().let { it.average() - it.median() }
fun Array<out Double>.skewDifference() = toDoubleArray().skewDifference()